//
//  MenuFirstDetailViewController.m
//  Products_B
//
//  Created by lanou on 16/5/31.
//  Copyright © 2016年 朋学友. All rights reserved.
//

#import "MenuFirstDetailViewController.h"
#import "Menudetail2TableViewCell.h"

#import "MenuZuofaModel.h"
#import "MenuZuofaTableViewCell.h"
#import "MwnuDetail2Shicai1TableViewCell.h"
#import "MenuDetail2ShiCai2TableViewCell.h"
#import "MenuDetailShiCai3TableViewCell.h"
#import "MenuDetail2ShicaiModel.h"
#import "MenuDetail2Xiangguan1TableViewCell.h"
#import "MenuDetailXiangguan2TableViewCell.h"
#import "MenuDetail3XiangguanTableViewCell.h"
#import "MenuXiangyiXiangkeModel.h"
#import "MenuXiangyiXiangke1TableViewCell.h"
#import "MenuXiangyiXinagke2TableViewCell.h"
@interface MenuFirstDetailViewController ()<UITableViewDataSource,UITableViewDelegate,UIScrollViewDelegate>
//  头视图

@property (nonatomic,strong)MenuFirstModel *fistModel;
@property (nonatomic, strong)UIView *headView;
@property (nonatomic, assign)CGFloat width;
@property (nonatomic, assign)CGFloat bigWidth;

@property (nonatomic ,strong)UITableView *bigTableView;
@property (nonatomic, strong)UIButton *button1;
@property (nonatomic, strong)UIButton *button2;
@property (nonatomic, strong)UIButton *button3;
@property (nonatomic, strong)UIButton *button4;
@property (nonatomic, strong)UIView *lineView;
@property (nonatomic, assign)CGFloat lastContentOffsetY;
@property (nonatomic, strong)UIView *navView;
@property (nonatomic, assign)NSInteger index;
@property (nonatomic, strong)UILabel *pinlunLabel;

@property (nonatomic, strong)NSMutableArray *oneModelArray;
@property (nonatomic, strong)NSString *commentString;
@property (nonatomic, strong)NSString *picImageString;
@property (nonatomic, strong)NSMutableArray *twoModelArray1;
@property (nonatomic, strong)NSMutableArray *twoModelArray2;
@property (nonatomic, strong)NSString *xiangguanImageStr;
@property (nonatomic, strong)NSString *xiangguanTitleStr;
@property (nonatomic, strong)NSString *xiangguanContentStr;
@property (nonatomic, strong)NSString *xiangyiImage;
@property (nonatomic, strong)NSMutableArray *xiangyiArray;
@property (nonatomic, strong)NSMutableArray *xiangkeArray;

@property (nonatomic, strong)UIScrollView *scrollView;
@property (nonatomic, strong)UITableView *tableView1;
@property (nonatomic, strong)UITableView *tableView2;
@property (nonatomic, strong)UITableView *tableView3;
@property (nonatomic, strong)UITableView *tableView4;
@property (nonatomic,strong)UILabel *titleLabel;
@property (nonatomic, strong)UIImageView *picImageView;
@property (nonatomic,strong)UILabel *titleLabel1;
@property (nonatomic,strong)UILabel *contentLabel;
@property (nonatomic,strong)UILabel *cLabel1;
@property (nonatomic,strong)UILabel *cLabel2;
@property (nonatomic,strong)UILabel *cLabel3;
@end

@implementation MenuFirstDetailViewController

- (void)viewDidLoad {
    
    //  做法 http://api.izhangchu.com/?appVersion=4.4&sysVersion=9.0.2&devModel=iPhone
    //  dishes_id=14733&methodName=DishesView&token=0&user_id=0&version=4.4
    
    
    
    //  食材 http://api.izhangchu.com/?appVersion=4.4&sysVersion=9.0.2&devModel=iPhone
    //  dishes_id=14733&methodName=DishesMaterial&token=0&user_id=0&version=4.4
    
    
    //  相关常识
//  http://api.izhangchu.com/?appVersion=4.4&sysVersion=9.0.2&devModel=iPhone  dishes_id=14733&methodName=DishesCommensense&token=0&user_id=0&version=4.4
    
    //  相宜相克
    // http://api.izhangchu.com/?appVersion=4.4&sysVersion=9.0.2&devModel=iPhone
    // dishes_id=14733&methodName=DishesSuitable&token=0&user_id=0&version=4.4
    
    
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //  加头 视图
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self addHeadView];
    
   
    self.bigTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kWidth, kHeight - 40) style:(UITableViewStylePlain)];
    self.bigTableView.delegate = self;
    self.bigTableView.dataSource = self;
    [self.bigTableView registerClass:[Menudetail2TableViewCell class] forCellReuseIdentifier:@"Menudetail2TableViewCell"];
    [self.view addSubview:_bigTableView];
    _bigTableView.tableHeaderView = self.headView;
    self.view.backgroundColor = [UIColor whiteColor];
    UIButton *backButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    backButton.frame = CGRectMake(20, 30, 20, 20);
    [backButton setBackgroundImage:[UIImage imageNamed:@"menuBack"] forState:(UIControlStateNormal)];
    [backButton addTarget:self action:@selector(backButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:backButton];
    self.navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kWidth, 70)];
    self.navView.backgroundColor = [UIColor whiteColor];
    self.navView.hidden = YES;
    [self.view addSubview:_navView];
    UIButton *backButton1 = [UIButton buttonWithType:(UIButtonTypeSystem)];
    backButton1.frame = CGRectMake(20, 30, 20, 20);
    [backButton1 setBackgroundImage:[UIImage imageNamed:@"menuBack"] forState:(UIControlStateNormal)];
    [backButton1 addTarget:self action:@selector(backButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(kWidth/2-50, 30, 100, 20)];
//    titleLabel.text = self.model.title;
    _titleLabel.textAlignment = NSTextAlignmentCenter;
    _titleLabel.font = [UIFont systemFontOfSize:14];
    [self.navView addSubview:_titleLabel];
    
    [self.navView addSubview:backButton1];
    [self addDownView];
    
    [self requestZuofaData];
    [self requestShicaiData];
    [self requestXiangGuanChangShiData];
    [self requestXiangYiXiangKeData];
}
#pragma mark - 添加头视图-
- (void)addHeadView{
    self.headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 410, kWidth)];
    _picImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kWidth, 200)];
    
    UIButton *bofangButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    bofangButton.frame = CGRectMake(kWidth/2-20, 100-20, 40, 40);
    [bofangButton setBackgroundImage:[UIImage imageNamed:@"menubobo"] forState:(UIControlStateNormal)];
    [bofangButton addTarget:self action:@selector(bofangButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.headView addSubview:_picImageView];
    [_picImageView addSubview: bofangButton];
    
    UIImageView *imageview1 = [[UIImageView alloc]initWithFrame:CGRectMake((kWidth - 210) / 4, 160, 20, 20)];
    UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake((kWidth - 210) / 4 + 20, 160, 50, 20)];
    
    UIImageView *imageView2 = [[UIImageView alloc]initWithFrame:CGRectMake((kWidth - 210) / 4 * 2+ 20 + 50, 160, 20, 20)];
    
    UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake((kWidth - 210) / 4 * 2+ 20 + 50 + 20, 160, 50, 20)];
    UIImageView *imageView3 = [[UIImageView alloc]initWithFrame:CGRectMake((kWidth - 210) / 4 * 3+ 20 + 50 + 20 + 50, 160, 20, 20)];
    UILabel *label3 = [[UILabel alloc]initWithFrame:CGRectMake((kWidth - 210) / 4 * 3+ 20 + 50 + 20 + 50 + 20, 160, 50, 20)];
    imageview1.image = [UIImage imageNamed:@"menubb"];
    imageView2.image = [UIImage imageNamed:@"menubb"];
    imageView3.image = [UIImage imageNamed:@"menuhuancun"];
    label1.text = @"食材准备";
    label2.text = @"制作步骤";
    label3.text = @"缓存";
    label1.textColor = [UIColor yellowColor];
    label1.font = [UIFont systemFontOfSize:11];
    label2.textColor = [UIColor yellowColor];
    label2.font = [UIFont systemFontOfSize:11];
    label3.textColor = [UIColor yellowColor];
    label3.font = [UIFont systemFontOfSize:11];
    _picImageView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap1Action:)];
    imageview1.userInteractionEnabled = YES;
    [imageview1 addGestureRecognizer:tap1];
    
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap2Action:)];
    imageView2.userInteractionEnabled = YES;
    [imageView2 addGestureRecognizer:tap2];
    
    UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap3Action:)];
    imageView3.userInteractionEnabled = YES;
    [imageView3 addGestureRecognizer:tap3];
    
    
    
    [_picImageView addSubview:label1];
    [_picImageView addSubview:label2];
    [_picImageView addSubview:label3];
    [_picImageView addSubview:imageview1];
    [_picImageView addSubview:imageView2];
    [_picImageView addSubview:imageView3];
    
    _titleLabel1 = [[UILabel alloc]initWithFrame:CGRectMake(20, 200, 200, 30)];
    _titleLabel1.font = [UIFont systemFontOfSize:14];
    //    titleLabel.text = self.model.title;
    
    [self.headView addSubview:_titleLabel1];
    
    UIImageView *lefiImageView = [[UIImageView alloc]initWithFrame:CGRectMake(20, 230, 20, 20)];
    //    lefiImageView.backgroundColor = [UIColor grayColor];
    lefiImageView.image = [UIImage imageNamed:@"menufeiji"];
    self.bigWidth = 20;
    
    //    for (int i = 0; i < self.model.bigSpArray.count; i++) {
       _contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 290, kWidth - 40, 50)];
    _contentLabel.numberOfLines = 0;
    _contentLabel.textColor = [UIColor grayColor];
    _contentLabel.font = [UIFont systemFontOfSize:13];
//    NSString *string =  [[self.fistModel.content mutableCopy]stringByReplacingOccurrencesOfString:@"…" withString:@""];
//    _contentLabel.text = string;
    
    UIImageView *icImageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(50, 350, 20, 20)];
    icImageView1.image = [UIImage imageNamed:@"menuwan0"];
    UIImageView *icimageView2 = [[UIImageView alloc]initWithFrame:CGRectMake(kWidth / 2 - 10, 350, 20, 20)];
    icimageView2.image = [UIImage imageNamed:@"menuwan2"];
    UIImageView *icImageView3 = [[UIImageView alloc]initWithFrame:CGRectMake(kWidth - 50 - 20, 350, 20, 20)];
    icImageView3.image = [UIImage imageNamed:@"menuwan1"];
    
    _cLabel1 = [[UILabel alloc]initWithFrame:CGRectMake(25, 370, 70, 20)];
    _cLabel2 = [[UILabel alloc]initWithFrame:CGRectMake(kWidth / 2 - 60, 370, 120, 20)];
    _cLabel3 = [[UILabel alloc]initWithFrame:CGRectMake(kWidth - 20 - 70, 370, 50, 20)];
    _cLabel1.font = [UIFont systemFontOfSize:13];
    _cLabel1.textColor = [UIColor grayColor];
    _cLabel3.textAlignment = NSTextAlignmentCenter;
    _cLabel1.textAlignment = NSTextAlignmentCenter;
    _cLabel2.textAlignment = NSTextAlignmentCenter;
    _cLabel2.font = [UIFont systemFontOfSize:13];
    _cLabel2.textColor = [UIColor grayColor];
    _cLabel3.font = [UIFont systemFontOfSize:13];
    _cLabel3.textColor = [UIColor grayColor];
 
    [self.headView addSubview:_cLabel1];
    [self.headView addSubview:_cLabel2];
    [self.headView addSubview:_cLabel3];
    [self.headView addSubview:icImageView1];
    [self.headView addSubview:icimageView2];
    [self.headView addSubview:icImageView3];
    [self.headView addSubview:_contentLabel];
    [self.headView addSubview:lefiImageView];
    [self.headView addSubview:_picImageView];
    
    //    [self.view addSubview:_headView];
    
    
    
}
#pragma mark - 做法的网络请求 - 
- (void)requestZuofaData{
    [RequestManager requestWithUrl:@"http://api.izhangchu.com/" requestType:(RequestTypePOST) parDic:@{@"dishes_id":self.dishes_id,@"methodName":@"DishesView",@"token":@"0",@"user_id":@"0",@"version":@"4.4"} finish:^(NSData *data) {
        NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        self.commentString = jsonDic[@"data"][@"comment_count"];
        _pinlunLabel.text = self.commentString;
        //  做法
        self.oneModelArray = [MenuZuofaModel modelConfigureWithDic:jsonDic];
        
      self.fistModel =  [MenuFirstModel modelConfigureWithJsonDic:jsonDic];
        _titleLabel.text = self.fistModel.dishes_name;
        [_picImageView sd_setImageWithURL:[NSURL URLWithString:self.fistModel.image] placeholderImage:nil completed:nil];
        _titleLabel1.text = self.fistModel.dishes_name;
        _contentLabel.text = self.fistModel.material_desc;
        _cLabel1.text = [NSString stringWithFormat:@"难度:%@",self.fistModel.hard_level];
        _cLabel2.text = [NSString stringWithFormat:@"烹饪时间:%@",self.fistModel.cooking_time];
        _cLabel3.text = [NSString stringWithFormat:@"口味:%@",self.fistModel.taste];
        NSLog(@"%@",self.fistModel.image);
        for (int i = 0; i < self.fistModel.bigSpArray.count; i++) {
            
            UIButton *button = [UIButton buttonWithType:(UIButtonTypeSystem)];
            button.tag = 500 + i;
            
            self.bigWidth += _width  + 20 ;
            
            [button addTarget:self action:@selector(smallButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
            button.titleLabel.font = [UIFont systemFontOfSize:14];
            NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:14] forKey:NSFontAttributeName];
            
            CGRect bounds = [self.fistModel.bigSpArray[i] boundingRectWithSize:CGSizeMake(10000, 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
            self.width = bounds.size.width;
            [button setTitle:self.fistModel.bigSpArray[i] forState:(UIControlStateNormal)];
            if (i == 4) {
                if (self.bigWidth + self.width + 20 > kWidth) {
                    button.frame = CGRectMake(40, 260, self.width, 20);
                    [button setTintColor:[UIColor orangeColor]];
                    button.layer.borderWidth = 1;
                    button.layer.borderColor = [UIColor orangeColor].CGColor;
                    button.layer.cornerRadius = 4;
                    button.layer.masksToBounds = YES;
                    [self.headView addSubview:button];
                    break;
                }
            }
            if (i == 0) {
                NSLog(@"%f",self.width);
                button.frame = CGRectMake(40, 230, self.width, 20);
            }else{
                button.frame = CGRectMake(self.bigWidth , 230, self.width, 20);
            }
            
            [button setTintColor:[UIColor orangeColor]];
            button.layer.borderWidth = 1;
            button.layer.borderColor = [UIColor orangeColor].CGColor;
            button.layer.cornerRadius = 10;
            button.layer.masksToBounds = YES;
            [self.headView addSubview:button];
            
        }

        [self.bigTableView reloadData];
    } error:nil];
}
#pragma mark - 食材的网络请求 - 
- (void)requestShicaiData{
    [RequestManager requestWithUrl:@"http://api.izhangchu.com/" requestType:(RequestTypePOST) parDic:@{@"dishes_id":self.dishes_id,@"methodName":@"DishesMaterial",@"token":@"0",@"user_id":@"0",@"version":@"4.4"} finish:^(NSData *data) {
        NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        self.picImageString = jsonDic[@"data"][@"material_image"];
       self.twoModelArray1 = [MenuDetail2ShicaiModel modelArray1ConfigureWithDic:jsonDic];
       self.twoModelArray2 = [MenuDetail2ShicaiModel modelArray2ConfigureWithDic:jsonDic];
        NSLog(@"%@",self.twoModelArray2);
       
      [self.bigTableView reloadData];
        
    } error:nil];
}
#pragma mark - 相关常识的网络请求 - 
- (void)requestXiangGuanChangShiData{
    [RequestManager requestWithUrl:@"http://api.izhangchu.com/" requestType:(RequestTypePOST) parDic:@{@"dishes_id":self.dishes_id,@"methodName":@"DishesCommensense",@"token":@"0",@"user_id":@"0",@"version":@"4.4"} finish:^(NSData *data) {
        NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        self.xiangguanImageStr = jsonDic[@"data"][@"image"];
        self.xiangguanTitleStr = jsonDic[@"data"][@"nutrition_analysis"];
        self.xiangguanContentStr = jsonDic[@"data"][@"production_direction"];
        NSLog(@"%@",self.xiangguanContentStr);
        [self.bigTableView reloadData];
    } error:nil];
}
#pragma mark - 相宜相克的网络请求 - 
- (void)requestXiangYiXiangKeData{
    [RequestManager requestWithUrl:@"http://api.izhangchu.com/" requestType:(RequestTypePOST) parDic:@{@"dishes_id":self.dishes_id,@"methodName":@"DishesSuitable",@"token":@"0",@"user_id":@"0",@"version":@"4.4"} finish:^(NSData *data) {
        NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"%@",jsonDic);
        self.xiangyiImage = jsonDic[@"data"][@"material"][@"image"];
        self.xiangyiArray = [MenuXiangyiXiangkeModel modelXiangyiWithDic:jsonDic];
        self.xiangkeArray = [MenuXiangyiXiangkeModel modelXinagkeWithDic:jsonDic];
        [self.bigTableView reloadData];
    } error:nil];
}
#pragma mark - 返回行数 -
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView == self.bigTableView) {
        return 1;
    }
    if (tableView == self.tableView1) {
        return self.oneModelArray.count;
    }
    if (tableView == self.tableView2) {
        return self.twoModelArray1.count + self.twoModelArray2.count +1;
    }
    if (tableView == self.tableView3) {
        return 3;
    }
    if (tableView == self.tableView4) {
        if (section == 0) {
            return 1;
        }
        if (section == 1) {
            return self.xiangyiArray.count;
        }
        return self.xiangkeArray.count;
    }
    return 0;
}
#pragma mark - 返回分区数 -
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    if (tableView == self.tableView4) {
        return 3;
    }
    return 1;
}
#pragma mark - 返回cell - 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView == self.bigTableView) {
    
    Menudetail2TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Menudetail2TableViewCell" forIndexPath:indexPath];
        self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, kWidth, 170 * self.oneModelArray.count)];
        self.scrollView.contentSize = CGSizeMake(kWidth *4, self.oneModelArray.count);
        self.scrollView.delegate = self;
        self.scrollView.pagingEnabled = YES;
        self.scrollView.bounces = NO;
        
        self.tableView1 = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kWidth, 170 *self.oneModelArray.count) style:(UITableViewStylePlain)];
//        self.tableView1.backgroundColor = [UIColor redColor];
        self.tableView1.delegate = self;
        self.tableView1.dataSource = self;
        self.tableView1.bounces = NO;
        [self.tableView1 registerClass:[MenuZuofaTableViewCell class] forCellReuseIdentifier:@"MenuZuofaTableViewCell"];
        
        [self.scrollView addSubview:self.tableView1];
       
        self.tableView2 = [[UITableView alloc]initWithFrame:CGRectMake(kWidth, 0, kWidth, 170 *self.oneModelArray.count) style:(UITableViewStylePlain)];
        self.tableView2.delegate = self;
        self.tableView2.dataSource = self;
        self.tableView2.bounces = NO;
        [self.tableView2 registerClass:[MwnuDetail2Shicai1TableViewCell class] forCellReuseIdentifier:@"MwnuDetail2Shicai1TableViewCell"];
        [self.tableView2 registerClass:[MenuDetail2ShiCai2TableViewCell class] forCellReuseIdentifier:@"MenuDetail2ShiCai2TableViewCell"];
    
        [self.tableView2 registerClass:[MenuDetailShiCai3TableViewCell class] forCellReuseIdentifier:@"MenuDetailShiCai3TableViewCell"];
        [self.scrollView addSubview:_tableView2];
     
        self.tableView3 = [[UITableView alloc]initWithFrame:CGRectMake(kWidth *2, 0, kWidth, 170 *self.oneModelArray.count) style:(UITableViewStylePlain)];
        self.tableView3.delegate = self;
        self.tableView3.dataSource = self;
        self.tableView3.bounces = NO;
        [self.tableView3 registerClass:[MenuDetail2Xiangguan1TableViewCell class] forCellReuseIdentifier:@"MenuDetail2Xiangguan1TableViewCell"];
        [self.tableView3 registerClass:[MenuDetailXiangguan2TableViewCell class] forCellReuseIdentifier:@"MenuDetailXiangguan2TableViewCell"];
        [self.tableView3 registerClass:[MenuDetail3XiangguanTableViewCell class] forCellReuseIdentifier:@"MenuDetail3XiangguanTableViewCell"];
//        self.tableView3.backgroundColor = [UIColor magentaColor];
        [self.scrollView addSubview:_tableView3];
        self.tableView4 = [[UITableView alloc]initWithFrame:CGRectMake(kWidth *3, 0, kWidth, 170*self.oneModelArray.count) style:(UITableViewStylePlain)];
        self.tableView4.delegate = self;
        self.tableView4.dataSource = self;
        self.tableView4.bounces = NO;
        [self.tableView4 registerClass:[MenuXiangyiXiangke1TableViewCell class] forCellReuseIdentifier:@"MenuXiangyiXiangke1TableViewCell"];
        [self.tableView4 registerClass:[MenuXiangyiXinagke2TableViewCell class] forCellReuseIdentifier:@"MenuXiangyiXinagke2TableViewCell"];
        [self.scrollView addSubview:_tableView4];
         [cell addSubview:_scrollView];
    return cell;
   }
    if (tableView == self.tableView1) {
        MenuZuofaTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MenuZuofaTableViewCell" forIndexPath:indexPath];
        MenuZuofaModel *model = self.oneModelArray[indexPath.row];
        [cell.picImageView sd_setImageWithURL:[NSURL URLWithString:model.dishes_step_image] placeholderImage:nil completed:nil];
        cell.zuofaLabel.font = [UIFont systemFontOfSize:14];
        cell.zuofaLabel.textColor = [UIColor grayColor];
        cell.zuofaLabel.numberOfLines = 0;
        cell.zuofaLabel.text = [NSString stringWithFormat:@"%ld,%@",indexPath.row +1,model.dishes_step_desc];
//        cell.backgroundColor = [UIColor magentaColor];
        return cell;
    }
    if (tableView == self.tableView2) {
        if (indexPath.row == 0) {
        MwnuDetail2Shicai1TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MwnuDetail2Shicai1TableViewCell" forIndexPath:indexPath];
            NSLog(@"%@",self.picImageString);
        [cell.picImageView sd_setImageWithURL:[NSURL URLWithString:self.picImageString] placeholderImage:nil completed:nil];
            return cell;
       }
        if (indexPath.row <= self.twoModelArray1.count) {
            MenuDetail2ShiCai2TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MenuDetail2ShiCai2TableViewCell" forIndexPath:indexPath];
            MenuDetail2ShicaiModel *model = self.twoModelArray1[indexPath.row - 1];
            cell.titlelabel.text = model.material_name;
            cell.numLabel.text = model.material_weight;
            return cell;
        }
        MenuDetailShiCai3TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MenuDetailShiCai3TableViewCell" forIndexPath:indexPath];
        MenuDetail2ShicaiModel *model = self.twoModelArray2[indexPath.row - 1 - self.twoModelArray1.count];
        [cell.picImageView sd_setImageWithURL:[NSURL URLWithString:model.image] placeholderImage:nil completed:nil];
        cell.titleLabel.text = model.title;
        return cell;
    }
    if (tableView == self.tableView3) {
        if (indexPath.row == 0) {
            MenuDetail2Xiangguan1TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MenuDetail2Xiangguan1TableViewCell" forIndexPath:indexPath];
            [cell.picImageView sd_setImageWithURL:[NSURL URLWithString:self.xiangguanImageStr] placeholderImage:nil completed:nil];
            return cell;
        }
        if (indexPath.row == 1) {
            MenuDetailXiangguan2TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MenuDetailXiangguan2TableViewCell" forIndexPath:indexPath];
            cell.contentLabel.text = self.xiangguanTitleStr;
            NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:13] forKey:NSFontAttributeName];
            CGRect bounds = [self.xiangguanTitleStr boundingRectWithSize:CGSizeMake(kWidth - 40, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
            NSLog(@"%f",bounds.size.height);
            cell.contentLabel.frame = CGRectMake(20, 40, kWidth - 40, bounds.size.height);
            return cell;
        }
        MenuDetail3XiangguanTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MenuDetail3XiangguanTableViewCell" forIndexPath:indexPath];
        cell.contentLabel.text = self.xiangguanContentStr;
        NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:13] forKey:NSFontAttributeName];
        CGRect bounds = [self.xiangguanContentStr boundingRectWithSize:CGSizeMake(kWidth - 40, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
        cell.contentLabel.frame = CGRectMake(20, 40, kWidth - 40, bounds.size.height);
        
        return cell;
    }
    if (tableView == self.tableView4) {
        if (indexPath.section == 0) {
            MenuXiangyiXiangke1TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MenuXiangyiXiangke1TableViewCell" forIndexPath:indexPath];
            [cell.picImageView sd_setImageWithURL:[NSURL URLWithString:self.xiangyiImage] placeholderImage:nil completed:nil];
            return cell;
        }
        
        MenuXiangyiXinagke2TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MenuXiangyiXinagke2TableViewCell" forIndexPath:indexPath];
        if (indexPath.section == 1) {
            cell.titleLabel.text = [self.xiangyiArray[indexPath.row] material_name];
            cell.contentLabel.text = [self.xiangyiArray[indexPath.row ] suitable_desc];
            cell.titleLabel.font = [UIFont systemFontOfSize:14];
            cell.contentLabel.font = [UIFont systemFontOfSize:13];
            cell.contentLabel.textColor = [UIColor grayColor];
            MenuXiangyiXiangkeModel *model = self.xiangyiArray[indexPath.row];
            [cell.picImageView sd_setImageWithURL:[NSURL URLWithString:model.image] placeholderImage:nil completed:nil];
            return cell;
        }
        cell.titleLabel.text = [self.xiangkeArray[indexPath.row] material_name];
        cell.contentLabel.text = [self.xiangkeArray[indexPath.row ] suitable_desc];
        cell.titleLabel.font = [UIFont systemFontOfSize:14];
        cell.contentLabel.font = [UIFont systemFontOfSize:13];
        cell.contentLabel.textColor = [UIColor grayColor];
        MenuXiangyiXiangkeModel *model = self.xiangkeArray[indexPath.row];
        [cell.picImageView sd_setImageWithURL:[NSURL URLWithString:model.image] placeholderImage:nil completed:nil];
        return cell;
        
    }
    return nil;
}
#pragma mark - 返回cell 的高度 - 
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView == self.bigTableView) {
        return 170 * self.oneModelArray.count;
    }
    if (tableView == self.tableView1) {
        return 170;
    }
    if (tableView == self.tableView2) {
        if (indexPath.row == 0) {
            return 160;
        }
        if (indexPath.row <= self.twoModelArray1.count) {
            return 30;
        }
        return 160;
    }
    if (tableView == self.tableView3) {
        if (indexPath.row == 0) {
            return 160;
        }
        if (indexPath.row == 1) {
            NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:13] forKey:NSFontAttributeName];
            CGRect bounds = [self.xiangguanTitleStr boundingRectWithSize:CGSizeMake(kWidth - 40, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
            return 40 +bounds.size.height;
        }
        NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:13] forKey:NSFontAttributeName];
        CGRect bounds = [self.xiangguanContentStr boundingRectWithSize:CGSizeMake(kWidth - 40, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
        return 40 +bounds.size.height;
    }
    if (tableView == self.tableView4) {
        if (indexPath.section == 0) {
            return 160;
        }
        return 70;
    }
    return 0;
}
#pragma mark  - 返回区头 -
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (tableView == self.bigTableView) {
        
    UIView *TopView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kWidth, 40)];
    self.button1 = [[UIButton alloc]initWithFrame:CGRectMake(kWidth / 4 *0, 10, kWidth/4, 40)];
    self.button2 = [[UIButton alloc]initWithFrame:CGRectMake(kWidth / 4 *1, 10,kWidth / 4 , 40)];
    self.button3 = [[UIButton alloc]initWithFrame:CGRectMake(kWidth / 4 *2, 10,kWidth / 4 , 40)];
    self.button4 = [[UIButton alloc]initWithFrame:CGRectMake(kWidth / 4 *3, 10,kWidth / 4 , 40)];
    [self.button1 setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    self.lineView = [[UIView alloc]initWithFrame:CGRectMake(kWidth / 4 * 0, 38, kWidth/4, 2)];
    self.lineView.backgroundColor = [UIColor orangeColor];
    [TopView addSubview:_lineView];
    
    [self.button2 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
    [self.button3 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
    [self.button4 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
    [self.button1 setTitle:@"做法" forState:(UIControlStateNormal)];
    [self.button2 setTitle:@"食材" forState:(UIControlStateNormal)];
    [self.button3 setTitle:@"相关常识" forState:(UIControlStateNormal)];
    [self.button4 setTitle:@"相宜相克" forState:(UIControlStateNormal)];
    
    [self.button1 addTarget:self action:@selector(button1Action:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.button2 addTarget:self action:@selector(button2Action:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.button3 addTarget:self action:@selector(button3Action:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.button4 addTarget:self action:@selector(button4Action:) forControlEvents:(UIControlEventTouchUpInside)];
    
    [TopView addSubview:_button1];
    [TopView addSubview:_button2];
    [TopView addSubview:_button3];
    [TopView addSubview:_button4];
    
    
    return TopView;
    }
    if (tableView == self.tableView4) {
        if (section != 0) {
            UIView *myView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kWidth, 30)];
            UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(kWidth/2 - 150, 0, 300, 30)];
            titleLabel.textAlignment = NSTextAlignmentCenter;
            [myView addSubview:titleLabel];
            if (section == 1) {
                titleLabel.text = @"与搭配相宜的食物";
            }if (section == 2) {
                titleLabel.text = @"与搭配相克的食物";
            }
            
            return myView;
        }
    }
    return nil;
}
#pragma mark - 返回区头高度 -
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (tableView == self.bigTableView) {
        return 50;
    }
    if (tableView == self.tableView4) {
        if (section != 0) {
            return 30;
        }
    }
    return 0;
}

- (void)backButtonAction:(UIButton *)button{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - 刚开始拖拽 -
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    if (scrollView == self.bigTableView) {
            self.lastContentOffsetY = scrollView.contentOffset.y;
    }

}
#pragma mark 滚动的代理方法 -
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
   
    
    if (scrollView == self.bigTableView) {
        NSLog(@"a");
        int flag = 0;
        if (scrollView.contentOffset.y >=330) {
            NSLog(@"0000");
            self.index++;
            self.navView.hidden = NO;
            
            self.bigTableView.frame = CGRectMake(0, 70, kWidth, kHeight-70);
            //            NSLog(@"%f",scrollView.contentOffset.y);
            flag = 1;
        }else{
            NSLog(@"b");
            self.index = 0;
        }
        if (self.index == 1) {
            NSLog(@"c");
            scrollView.contentOffset = CGPointMake(0, 400);
        }
        if (scrollView.contentOffset.y < self.lastContentOffsetY) {
            NSLog(@"d");
            if (scrollView.contentOffset.y <= 330) {
                self.navView.hidden = YES;
                self.bigTableView.frame = CGRectMake(0, 0, kWidth, kHeight);
            }
            
            
        }
        
        
        
        
    }}

#pragma mark - 添加下面的view - 
- (void)addDownView{
    UIView *downView = [[UIView alloc]initWithFrame:CGRectMake(0, kHeight - 30, kWidth, 40)];
    CGFloat space = (kWidth - 240)/5;
    UIButton *zanButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    zanButton.frame = CGRectMake(space, 0, 30, 30);
    [zanButton setBackgroundImage:[UIImage imageNamed:@"menuwujiaoxing"] forState:(UIControlStateNormal)];
    [zanButton addTarget:self action:@selector(zanButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    UILabel *zanLabel = [[UILabel alloc]initWithFrame:CGRectMake(space +30, 0, 30, 30)];
    UIButton *pinlunButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    pinlunButton.frame = CGRectMake(space *2 + 60, 0, 30, 30);
    [pinlunButton addTarget:self action:@selector(pinglunButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [pinlunButton setBackgroundImage:[UIImage imageNamed:@"menupinglun"] forState:(UIControlStateNormal)];
    _pinlunLabel = [[UILabel alloc]initWithFrame:CGRectMake(space *2 +90, 0, 30, 30)];
    _pinlunLabel.textAlignment = NSTextAlignmentCenter;
    _pinlunLabel.textColor = [UIColor grayColor];
    UIButton *fenxiangButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    [fenxiangButton setBackgroundImage:[UIImage imageNamed:@"menufenxiang"] forState:(UIControlStateNormal)];
    [fenxiangButton addTarget:self action:@selector(fenxiangButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    fenxiangButton.frame = CGRectMake(space *3 + 120, 0, 30, 30);
    UIButton *paizhaoButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    [paizhaoButton setBackgroundImage:[UIImage imageNamed:@"menupaizhao"] forState:(UIControlStateNormal)];
    [paizhaoButton addTarget:self action:@selector(paizhaoButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    paizhaoButton.frame = CGRectMake(space *4 + 180, 0, 30, 30);
    
    
    [downView addSubview:zanButton];
    [downView addSubview:zanLabel];
    [downView addSubview:pinlunButton];
    [downView addSubview:_pinlunLabel];
    [downView addSubview:fenxiangButton];
    [downView addSubview:paizhaoButton];
    downView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:downView];
}
#pragma mark - 赞 - 
- (void)zanButtonAction:(UIButton *)button{
    
}
#pragma mark - 评论 -
- (void)pinglunButtonAction:(UIButton *)button{
    
}
#pragma mark - 分享 - 
- (void)fenxiangButtonAction:(UIButton *)button{
    
}
#pragma mark - 拍照 -
- (void)paizhaoButtonAction:(UIButton *)button{
    
}
#pragma mark 描述菜的button - 
- (void)smallButtonAction:(UIButton *)button{
    
}
#pragma mark - 食材准备按钮 - 
- (void)tap1Action:(UITapGestureRecognizer *)tap{
    
}
#pragma mark - 制作步骤按钮 -
- (void)tap2Action:(UITapGestureRecognizer *)tap{
    
}
#pragma mark - 缓存按钮 -
- (void)tap3Action:(UITapGestureRecognizer *)tap{
    
}
#pragma mark -播放视频的按钮 -
- (void)bofangButtonAction:(UIButton *)button{
    //  播放源   self.model.video
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark 4个Button的点击方法 -
- (void)button1Action:(UIButton *)button{
    [self.button1 setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    self.lineView.frame = CGRectMake(kWidth/4*0, 38, kWidth/4, 2);
    [self.button2 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
    [self.button3 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
    [self.button4 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
    self.scrollView.contentOffset = CGPointMake(0, 0);
    
    
    self.bigTableView.contentOffset = CGPointMake(self.bigTableView.contentOffset.x, 400);
}
- (void)button2Action:(UIButton *)button{
    [self.button2 setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    self.lineView.frame = CGRectMake(kWidth/4*1, 38, kWidth/4, 2);
    [self.button1 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
    [self.button3 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
    [self.button4 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
    self.scrollView.contentOffset = CGPointMake(kWidth, 0);
    self.bigTableView.contentOffset = CGPointMake(self.bigTableView.contentOffset.x, 400);
}
- (void)button3Action:(UIButton *)button{
    [self.button3 setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    self.lineView.frame = CGRectMake(kWidth/4*2, 38, kWidth/4, 2);
    [self.button1 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
    [self.button2 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
    [self.button4 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
    self.scrollView.contentOffset = CGPointMake(kWidth *2, 0);
    self.bigTableView.contentOffset = CGPointMake(self.bigTableView.contentOffset.x, 400);
}
- (void)button4Action:(UIButton *)button{
    [self.button4 setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    self.lineView.frame = CGRectMake(kWidth/4*3, 38, kWidth/4, 2);
    [self.button1 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
    [self.button2 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
    [self.button3 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
    self.scrollView.contentOffset = CGPointMake(kWidth *3, 0);
    self.bigTableView.contentOffset = CGPointMake(self.bigTableView.contentOffset.x, 400);
}
#pragma mark - 滚动结束的代理方法 -
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    
    
    CGFloat index = self.scrollView.contentOffset.x/kWidth;
    if (scrollView == self.scrollView) {
        self.bigTableView.contentOffset = CGPointMake(self.bigTableView.contentOffset.x, 400);
        
        if (index == 0) {
            [self.button1 setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
            self.lineView.frame = CGRectMake(kWidth/4*0, 38, kWidth/4, 2);
            [self.button2 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
            [self.button3 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
            [self.button4 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
            self.scrollView.contentOffset = CGPointMake(0, 0);

            
        }
        if (index == 1) {
            [self.button2 setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
            self.lineView.frame = CGRectMake(kWidth/4*1, 38, kWidth/4, 2);
            [self.button1 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
            [self.button3 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
            [self.button4 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
            self.scrollView.contentOffset = CGPointMake(kWidth, 0);

        }
        if (index == 2) {
            [self.button3 setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
            self.lineView.frame = CGRectMake(kWidth/4*2, 38, kWidth/4, 2);
            [self.button1 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
            [self.button2 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
            [self.button4 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
            self.scrollView.contentOffset = CGPointMake(kWidth *2, 0);

        }
        if (index == 3) {
            [self.button4 setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
            self.lineView.frame = CGRectMake(kWidth/4*3, 38, kWidth/4, 2);
            [self.button1 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
            [self.button2 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
            [self.button3 setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
            self.scrollView.contentOffset = CGPointMake(kWidth *3, 0);

        }
        

    }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
